from model import db
import datetime

class Category(db.Model):
    __tablename__ = "category"  # 映射的数据表，不写默认是类名
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(128), nullable=False)
    icon = db.Column(db.String(128), nullable=True)
    CreateAt = db.Column(db.DateTime, default=datetime.datetime.now())
    # 创建类型和作品一对多的映射关系
    photos = db.relationship("Photo", backref="category", lazy=True)

    def keys(self):
        return ("id", 'name', 'icon', 'CreateAt', 'photos')

    def __getitem__(self, item):
        return getattr(self, item)
